/*
 * Copyright (c) 2010 Curtis Boyden.  All rights reserved. 
 * This software was developed by Curtis Boyden and is provided under the terms 
 * of the GNU Lesser General Public License, Version 2.1. You may not use 
 * this file except in compliance with the license. If you need a copy of the license, 
 * please go to http://www.gnu.org/licenses/lgpl-2.1.txt. The Original Code is ejMud
 * (Ewerp Java MUD).  The Initial Developer is Curtis Boyden.
 *
 * Software distributed under the GNU Lesser Public License is distributed on an "AS IS" 
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
 * the license for the specific language governing your rights and limitations.
 */

package com.ewerp.mud.entities;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import com.ewerp.mud.core.lifecycle.ILifecycleListener;
import com.ewerp.mud.core.plugin.AbstractPlugin;

public class EwerpContentManager extends AbstractPlugin implements IContentManager, ILifecycleListener {
    protected static EwerpContentManager instance = new EwerpContentManager();
    
    protected List<IEntity> objects = new LinkedList<IEntity>();
    
    public static EwerpContentManager getInstance() {
        if (instance == null) {
            instance = new EwerpContentManager();
        }

        return instance;
    }

    protected EwerpContentManager() {
    }
    
    @Override
    public IEntity fetchObject(IObjectId objectId) {
        IEntity result = null;
        
        for(IEntity object : objects) {
            if(object.getId().equals(objectId)) {
                result = object;
                break;
            }
        }
        
        return result;
    }

    @Override
    public void storeObject(IEntity object) {
        objects.add(object);
    }

    @Override
    public List<Class<?>> getInterfaces() {
        return Arrays.asList(new Class<?>[] { IContentManager.class });
    }

    @Override
    public void init() {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void start() {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void stop() {
        // TODO Auto-generated method stub
        
    }

}
